//验证用名的长度，及其是否重复
function checkStringName(name, nameMsg, type) {
	var text = $('#' + name).val();
	var boo = false;
	// 验证字符串是否符合规范及其长度范围
	// 将字符串转义
	var re = /^[0-9a-zA-Z\u4e00-\u9fa5]{1,15}$/;

	if (text.search(re) == -1) // 长度超过规定范围count
	{
		$("#" + nameMsg).html("<font color='red'>请输入 汉字、字母、数字,最多15个字符</font>");
		boo = false;
	} else // 长度未超过范围count,则验证重复性
	{

		// 验证重复性
		$.ajax({
			type : "POST",
			url : "../usermanage/isexistflowuser",
			data : "userName=" + text,
			async : false,
			success : function(data) {
				if ("1" == data) // 存在
				{
					if (type == 0) {
						$("#" + nameMsg)
								.html("<font color='red'>用户名已存在</font>");
						boo = false;
					} else {
						$("#" + nameMsg).html(
								"&nbsp;&nbsp;<img src='../images/ok.png' />");
						boo = true;
					}

				} else if ("0" == data) // 不存在
				{
					$("#" + nameMsg).html(
							"&nbsp;&nbsp;<img src='../images/ok.png' />");
					boo = true;
				}
			}
		});
	}
	return boo;
}

// 验证用户密码
function checkpassword(pw, name, nameMsg, count) {
	var text = $('#' + name).val();
	var password = $('#' + pw).val();
	var boo = false;
	// 验证字符串是否符合规范及其长度范围
	// 将字符串转义
	if (password != '') // text不为空字符串是，验证字符串长度，及其重复性
	{
		var n = 0;
		for ( var i = 0; i < password.length; i++) // 循环计算字符串的长度
		{
			if ($('#password').val().charCodeAt(i) > 255) {
				n = n + 2;
			} else {
				n = n + 1;
			}
		}
		if (n > count || n < 6) // 长度超过规定范围count或不够
		{
			$("#" + nameMsg).html(
					"<font color='red'>&nbsp;&nbsp;6~" + count + "个字符</font>");
			boo = false;
		} else {

			$("#" + nameMsg).html("&nbsp;&nbsp;<img src='../images/ok.png' />");
			boo = true;
		}
		if (text == password) {
			boo = false;
			$("#" + nameMsg).html(
					"<font color='red'>&nbsp;&nbsp;密码不能同用户名相同！！</font>");
		}
	} else {
		$("#" + nameMsg).html(
				"<font color='red'>&nbsp;&nbsp;6~" + count + "个字符</font>");
		boo = false;
	}
	return boo;
}

function getCheckBoxValue() {
	var count = $('#roleId').val();
	var boo = false;
	if(count == 0)
		{
		$("#roleMsg").html("<font color='red'>请选择角色</font>");
		boo = false;
		}
	else{
		$("#roleMsg").html("&nbsp;&nbsp;<img src='../images/ok.png' />");
		boo = true;
	}
	return boo;
}

function delByUserId(userId) {
	if (window.confirm('你确定要删除该记录！')) {
		location.href = '../usermanage/delflowuser?userId=' + userId;
	} else {
		return false;
	}
}

function updateByUserId(userId,status) {
	if (window.confirm('你确定要重置该记录吗！重置密码为123456')) {
		location.href = '../usermanage/resetpassword?userId=' + userId+"&status="+status;
	} else {
		return false;
	}
}
function updateStatusByUserId(userId, number,type) {
	var name = $('#show' + type).text();
	if (window.confirm('你确定要' + name + '此用户吗!')) {
		location.href = '../usermanage/updatestatus?userId=' + userId
				+ "&status=" + number;
	} else {
		return false;
	}
}

function checkOriginalPassword(originalPassword,originalPasswordMsg,password)
{
	var text = $('#' + originalPassword).val();
	var boo = false;

	if (text == "") // 长度超过规定范围count
	{
		$("#" + originalPasswordMsg).html("<font color='red'>请输入密码!</font>");
		boo = false;
	} else // 长度未超过范围count,则验证重复性
	{

		// 验证重复性
		$.ajax({
			type : "POST",
			url : "../usermanage/encryption",
			data : "password=" + text,
			async : false,
			success : function(data) {
				if (password == data) // 存在
				{
					$("#" + originalPasswordMsg).html("&nbsp;&nbsp;<img src='../images/ok.png' />");
					boo = true;
					
				} else if (password != data) // 不存在
				{
					$("#" + originalPasswordMsg).html(
					"<font color='red'>原密码不匹配</font>");
				boo = false;
				}
			}
		});
	}
	return boo;
}

function checkNewPassword(newPassword,newPasswordMsg,password,username)
{
	var text = $('#' + newPassword).val();
	var boo = false;
	if (text == "") // 长度超过规定范围count
	{
		$("#" + newPasswordMsg).html("<font color='red'>请输入新密码!</font>");
		boo = false;
	} 
	else if(text == username)
		 {
		 $("#" + newPasswordMsg).html("<font color='red'>密码不能用户名一致!</font>");
			boo = false;
		 }
	else // 长度未超过范围count,则验证重复性
	{

		// 验证重复性
		$.ajax({
			type : "POST",
			url : "../usermanage/encryption",
			data : "password=" + text,
			async : false,
			success : function(data) {
				if (password == data) // 存在
				{
					$("#" + newPasswordMsg).html(
							"<font color='red'>新密码不能同原密码相同！</font>");
						boo = false;
				} else if (password != data) // 不存在
				{
					$("#" + newPasswordMsg).html("&nbsp;&nbsp;<img src='../images/ok.png' />");
					boo = true;
				}
			}
		});
	}
	return boo;
}

function checkAgainPassword(againPassword,againPasswordMsg,newPassword)
{
	var newps = $('#' + newPassword).val();
	var againps = $('#' + againPassword).val();
	if (againps == "") // 长度超过规定范围count
	{
		$("#" + againPasswordMsg).html("<font color='red'>请再次输入新密码!</font>");
		boo = false;
	} 
	else if(newps != againps)
		{
		$("#" + againPasswordMsg).html(
		"<font color='red'>&nbsp;&nbsp;新密码和确认密码不同！！</font>");
		 return false;
		}
	else if(newps == againps)
		{
		$("#" + againPasswordMsg).html("&nbsp;&nbsp;<img src='../images/ok.png' />");
		 return true;
		}
}

function checkContent(name,nameMsg)
{
	var text = $('#' + name).val();
	var boo = true;
	// 验证字符串是否符合规范及其长度范围
	// 将字符串转义
	var re = /^[0-9a-zA-Z\u4e00-\u9fa5]{1,15}$/;

	if (text.search(re) == -1) // 长度超过规定范围count
	{
		$("#" + nameMsg).html("<font color='red'>请输入 汉字、字母、数字,最多15个字符</font>");
		boo = false;
	}else
		{
		$("#" + nameMsg).html("&nbsp;&nbsp;<img src='../images/ok.png' />");
		boo = true;
		}
	return boo;
}